package com.heihx.listener;

import com.heihx.entity.ShoppingCart;
import com.heihx.service.ShoppingCartService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RepetitionListener {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "trade.repetition.queue",durable = "true"),
            exchange = @Exchange(name = "trade.topic"),
            key = "repetition"))
    public void listenRepetition(List<ShoppingCart> shoppingCartList){
        shoppingCartService.saveBatch(shoppingCartList);
    }
}
